<template>
  <div class="approval-overview-container">
    <!-- 页面头部 -->
    <div class="page-header">
      <div class="header-left">
        <h2>OA审批流</h2>
        <p>企业办公自动化审批流程管理系统</p>
      </div>
     
    </div>

    <!-- 数据统计卡片 -->
    <div class="stats-cards">
      <div class="stat-card pending" @click="navigateToPendingTasks">
        <div class="stat-icon">
          <el-icon><Clock /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-number">{{ pendingTasks }}</div>
          <div class="stat-label">待办任务</div>
        </div>
        <div class="stat-action">
          <el-icon><ArrowRight /></el-icon>
        </div>
      </div>
      <div class="stat-card applications" @click="navigateToMyApplications">
        <div class="stat-icon">
          <el-icon><Document /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-number">{{ myApplications }}</div>
          <div class="stat-label">我的申请</div>
        </div>
        <div class="stat-action">
          <el-icon><ArrowRight /></el-icon>
        </div>
      </div>
      <div class="stat-card completed" @click="navigateToCompletedTasks">
        <div class="stat-icon">
          <el-icon><Check /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-number">{{ completedTasks }}</div>
          <div class="stat-label">已办任务</div>
        </div>
        <div class="stat-action">
          <el-icon><ArrowRight /></el-icon>
        </div>
      </div>
      <div class="stat-card efficiency" @click="navigateToStatistics">
        <div class="stat-icon">
          <el-icon><TrendCharts /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-number">{{ approvalEfficiency }}%</div>
          <div class="stat-label">审批效率</div>
        </div>
        <div class="stat-action">
          <el-icon><ArrowRight /></el-icon>
        </div>
      </div>
    </div>

    <!-- 功能导航 -->
    <div class="function-navigation">
      <h3>功能导航</h3>
      <div class="nav-grid">
        <div class="nav-item" @click="navigateToMyApplications">
          <div class="nav-icon">
            <el-icon><Document /></el-icon>
          </div>
          <div class="nav-content">
            <div class="nav-title">我的申请</div>
            <div class="nav-desc">查看和管理我发起的所有申请</div>
          </div>
        </div>
        
        <div class="nav-item" @click="navigateToPendingTasks">
          <div class="nav-icon">
            <el-icon><Clock /></el-icon>
          </div>
          <div class="nav-content">
            <div class="nav-title">待办任务</div>
            <div class="nav-desc">处理需要我审批的任务</div>
          </div>
        </div>
        
        <div class="nav-item" @click="navigateToCompletedTasks">
          <div class="nav-icon">
            <el-icon><Check /></el-icon>
          </div>
          <div class="nav-content">
            <div class="nav-title">已办任务</div>
            <div class="nav-desc">查看我已经处理完成的任务</div>
          </div>
        </div>
        
        <div class="nav-item" @click="navigateToCcToMe">
          <div class="nav-icon">
            <el-icon><Message /></el-icon>
          </div>
          <div class="nav-content">
            <div class="nav-title">抄送我的</div>
            <div class="nav-desc">查看抄送给我的流程信息</div>
          </div>
        </div>
        
        <div class="nav-item" @click="navigateToProcessMonitoring">
          <div class="nav-icon">
            <el-icon><Monitor /></el-icon>
          </div>
          <div class="nav-content">
            <div class="nav-title">流程监控</div>
            <div class="nav-desc">实时监控审批流程运行状态</div>
          </div>
        </div>
        
        <div class="nav-item" @click="navigateToStatistics">
          <div class="nav-icon">
            <el-icon><DataAnalysis /></el-icon>
          </div>
          <div class="nav-content">
            <div class="nav-title">统计报表</div>
            <div class="nav-desc">查看审批流程数据统计分析</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 最近活动 -->
    <div class="recent-activities">
      <h3>最近活动</h3>
      <div class="activity-list">
        <div v-for="(activity, index) in recentActivities" :key="index" class="activity-item">
          <div class="activity-icon">
            <el-icon :class="getActivityIconClass(activity.type)">
              <component :is="getActivityIcon(activity.type)" />
            </el-icon>
          </div>
          <div class="activity-content">
            <div class="activity-title">{{ activity.title }}</div>
            <div class="activity-desc">{{ activity.description }}</div>
            <div class="activity-time">{{ formatTime(activity.time) }}</div>
          </div>
          <div class="activity-action">
            <el-button size="small" type="primary" link @click="viewActivity(activity)">查看</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { 
  Plus, Clock, Document, Check, TrendCharts, Message, Monitor, DataAnalysis,
  ArrowRight, User, Warning, CircleCheck
} from '@element-plus/icons-vue'

const router = useRouter()

// 统计数据
const pendingTasks = ref(8)
const myApplications = ref(15)
const completedTasks = ref(42)
const approvalEfficiency = ref(87)

// 最近活动数据
const recentActivities = ref([
  {
    id: 1,
    type: 'application',
    title: '张三提交了请假申请',
    description: '申请时间：2024年1月20日-25日，等待您的审批',
    time: new Date('2024-01-15 14:30:00')
  },
  {
    id: 2,
    type: 'approval',
    title: '您的加班申请已通过',
    description: '李经理已同意您的加班申请，请注意劳逸结合',
    time: new Date('2024-01-15 13:20:00')
  },
  {
    id: 3,
    type: 'cc',
    title: '王五的报销申请已抄送给您',
    description: '客户招待费用报销，金额：1,200元',
    time: new Date('2024-01-15 11:45:00')
  },
  {
    id: 4,
    type: 'warning',
    title: '赵六的出差申请即将超时',
    description: '申请已等待审批2天，请及时处理',
    time: new Date('2024-01-15 09:15:00')
  }
])

// 导航方法
const navigateToMyApplications = () => {
  router.push('/approval/my-applications')
}

const navigateToPendingTasks = () => {
  router.push('/approval/pending-tasks')
}

const navigateToCompletedTasks = () => {
  router.push('/approval/completed-tasks')
}

const navigateToCcToMe = () => {
  router.push('/approval/cc-to-me')
}

const navigateToProcessMonitoring = () => {
  router.push('/approval/process-monitoring')
}

const navigateToStatistics = () => {
  router.push('/approval/statistics-reports')
}

// 活动相关方法
const getActivityIcon = (type) => {
  const iconMap = {
    'application': User,
    'approval': CircleCheck,
    'cc': Message,
    'warning': Warning
  }
  return iconMap[type] || User
}

const getActivityIconClass = (type) => {
  const classMap = {
    'application': 'activity-icon-primary',
    'approval': 'activity-icon-success',
    'cc': 'activity-icon-info',
    'warning': 'activity-icon-warning'
  }
  return classMap[type] || 'activity-icon-primary'
}

const viewActivity = (activity) => {
  // 根据活动类型跳转到对应页面
  switch (activity.type) {
    case 'application':
      navigateToPendingTasks()
      break
    case 'approval':
      navigateToMyApplications()
      break
    case 'cc':
      navigateToCcToMe()
      break
    case 'warning':
      navigateToPendingTasks()
      break
    default:
      ElMessage.info('查看活动详情')
  }
}

const formatTime = (time) => {
  if (!time) return ''
  const now = new Date()
  const diff = now - new Date(time)
  const minutes = Math.floor(diff / (1000 * 60))
  const hours = Math.floor(diff / (1000 * 60 * 60))
  const days = Math.floor(diff / (1000 * 60 * 60 * 24))
  
  if (days > 0) {
    return `${days}天前`
  } else if (hours > 0) {
    return `${hours}小时前`
  } else if (minutes > 0) {
    return `${minutes}分钟前`
  } else {
    return '刚刚'
  }
}

// 生命周期
onMounted(() => {
  // 可以在这里加载统计数据
  console.log('OA审批流概览页面已加载')
})
</script>

<style scoped>
.approval-overview-container {
  padding: 20px;
  background-color: #f5f5f5;
  min-height: 100vh;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding: 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-left h2 {
  margin: 0 0 8px 0;
  color: #303133;
  font-size: 24px;
  font-weight: 600;
}

.header-left p {
  margin: 0;
  color: #909399;
  font-size: 14px;
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  font-size: 24px;
  color: white;
}

.stat-card.pending .stat-icon {
  background: linear-gradient(135deg, #f39c12, #e67e22);
}

.stat-card.applications .stat-icon {
  background: linear-gradient(135deg, #3498db, #2980b9);
}

.stat-card.completed .stat-icon {
  background: linear-gradient(135deg, #27ae60, #229954);
}

.stat-card.efficiency .stat-icon {
  background: linear-gradient(135deg, #9b59b6, #8e44ad);
}

.stat-content {
  flex: 1;
}

.stat-number {
  font-size: 28px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 14px;
  color: #909399;
}

.stat-action {
  color: #909399;
  font-size: 16px;
}

.function-navigation {
  background: white;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  margin-bottom: 24px;
}

.function-navigation h3 {
  margin: 0 0 20px 0;
  color: #303133;
  font-size: 18px;
  font-weight: 600;
}

.nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 20px;
  border: 1px solid #e4e7ed;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.nav-item:hover {
  border-color: #409eff;
  background-color: #f0f9ff;
  transform: translateY(-1px);
}

.nav-icon {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: linear-gradient(135deg, #409eff, #337ecc);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  font-size: 20px;
  color: white;
}

.nav-content {
  flex: 1;
}

.nav-title {
  font-size: 16px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 4px;
}

.nav-desc {
  font-size: 14px;
  color: #909399;
  line-height: 1.4;
}

.recent-activities {
  background: white;
  padding: 24px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.recent-activities h3 {
  margin: 0 0 20px 0;
  color: #303133;
  font-size: 18px;
  font-weight: 600;
}

.activity-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.activity-item {
  display: flex;
  align-items: center;
  padding: 16px;
  border: 1px solid #e4e7ed;
  border-radius: 8px;
  transition: all 0.3s ease;
}

.activity-item:hover {
  border-color: #409eff;
  background-color: #f0f9ff;
}

.activity-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 16px;
  font-size: 16px;
  color: white;
}

.activity-icon-primary {
  background: linear-gradient(135deg, #409eff, #337ecc);
}

.activity-icon-success {
  background: linear-gradient(135deg, #67c23a, #529b2e);
}

.activity-icon-info {
  background: linear-gradient(135deg, #909399, #73767a);
}

.activity-icon-warning {
  background: linear-gradient(135deg, #e6a23c, #cf9236);
}

.activity-content {
  flex: 1;
}

.activity-title {
  font-size: 14px;
  font-weight: 600;
  color: #303133;
  margin-bottom: 4px;
}

.activity-desc {
  font-size: 13px;
  color: #606266;
  margin-bottom: 4px;
  line-height: 1.4;
}

.activity-time {
  font-size: 12px;
  color: #909399;
}

.activity-action {
  margin-left: 16px;
}
</style>